package com.halden.TRPG.controller;

import com.halden.TRPG.common.CodeEnum;
import com.halden.TRPG.common.MyException;
import com.halden.TRPG.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class MyExceptionHandler {

    @ExceptionHandler({MyException.class})
    public Result myExceptionHandler(MyException ex) {
        CodeEnum codeEnum = ex.getCodeEnum();
        log.error(codeEnum.getCode() + ": " + codeEnum.getMessage());
        return Result.error(codeEnum.getCode(),codeEnum.getMessage());
    }
}
